// 图文按钮

import 'package:flutter/material.dart';

class IconTextButton extends StatefulWidget {
  IconData icon;
  String text;
  int badge = 0;
  Color color;
  void Function()? onPressed;

  IconTextButton(
      {required this.icon,
      required this.text,
      this.badge = 0,
      this.color = const Color.fromARGB(255, 105, 104, 104),
      this.onPressed,
      super.key
      });

  @override
  State<StatefulWidget> createState() {
    return _IconTextButton();
  }
}

class _IconTextButton extends State<IconTextButton> {
  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 1 / 1,
      child: TextButton(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Stack(
              children: [
                Container(
                  height: 35,
                  width: 50,
                  padding: EdgeInsets.only(top: 15),
                  child: SizedBox(
                    height: 20,
                    child: Icon(
                      widget.icon,
                      color: widget.color,
                    ),
                  ),
                ),
                widget.badge! > 0
                    ? Positioned(
                        top: 2,
                        right: 0,
                        child: Container(
                          padding: EdgeInsets.only(left: 7, right: 7),
                          height: 20,
                          decoration: BoxDecoration(
                            color: Colors.red,
                            borderRadius: BorderRadius.circular(10),
                          ),
                          child: Center(
                            child: Text(
                              widget.badge.toString(),
                              style: const TextStyle(
                                  fontSize: 11, color: Colors.white),
                            ),
                          ),
                        ),
                      )
                    : const SizedBox(
                        height: 0,
                        width: 0,
                      )
              ],
            ),
            const SizedBox(
              height: 5,
            ),
            Text(
              widget.text,
              style: TextStyle(color: widget.color),
            )
          ],
        ),
        onPressed: widget.onPressed,
      ),
    );
  }
}
